﻿using System.Collections.Generic;
using System.Linq;
using Framework.Repository.Conventions;
using Framework.Repository.Testing;
using Xunit;

namespace Framework.Tests.Repository
{
    public class MapCompositeTest
    {
        [Fact]
        public void Should_Map_Composite()
        {
            using (var integrationTest = new IntegrationTest(new SqlServerCePersistence(), new AutoMappingTypeProvider().AddEntity<Composite>()))
            {
                var swa = new Composite("SWA");
                var mirror = new Composite("Mirror");
                mirror.Childs.Add(new Composite("Future"));
                mirror.Childs.Add(new Composite("Future2"));
                swa.Childs.Add(mirror);

                var compositeRepo = integrationTest.CreateRepository<Composite>();

                compositeRepo.Save(swa);

                Assert.True(compositeRepo.Where(x => x.Name == "SWA").Any());
            }
        }

        [Entity]
        public class Composite
        {
            protected Composite()
            {
            }

            public Composite(string name)
            {
                Name = name;
                Childs = new List<Composite>();
            }

            public virtual int Id { get; protected set; }
            public virtual string Name { get; set; }
            public virtual IList<Composite> Childs { get; protected set; }
        }
    }
}